<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/13 0013
 * Time: 下午 2:10
 */
namespace app\email\controller;

use think\Controller;
use think\Db;
use think\Loader;
use think\Request;
use common\library\Mini;

/**
 * 系统基础控制器：不需登录
 * @author  tangtanglove <dai_hang_love@126.com>
 */
class Base extends Controller
{
    /**
     * 邮箱校验
     * @author cms云商城
     */
    public function emailCheck()
    {
        //获得email邮箱
        $email = input('email');
        $token = input('token');

        $UserEmail = session('EmailUser');
        $res = Db::name('EmailCheck')->where(['username' => $UserEmail['username'], 'email' => $email])->find();
        if ($res) {
            $yz_token = md5($UserEmail['salt'] . $UserEmail['username'] . $res['passtime']);

            if ($yz_token == $token) {
                if (time() - $res['passtime'] > config('email_expiry')) {
                    return $this->error('该链接已过期');
                } else {
                    $session['username'] = $UserEmail['username'];
                    $session['email'] = $email;
                    $session['uuid'] = Db::name('Users')->where(['email' => $email, 'username' => $UserEmail['username']])->value('uuid');

                    session('editUser', $session);
                    return $this->success('请重设密码', url('base/editpass'));
                }
            } else {
                return $this->error('无效的链接');
            }

        } else {
            return $this->error('错误的链接');
        }
        return $this->themeFetch('editpass');
    }
}